<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page import="com.company.ems.model.User" %>
<%
    User user = (User) session.getAttribute("user");
    if (user == null) {
        response.sendRedirect("../login.jsp");
        return;
    }
%>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>员工管理系统 - 添加员工</title>
    <link rel="stylesheet" href="../css/style.css">
</head>
<body>
    <div class="container">
        <!-- 头部 -->
        <div class="header">
            <h1>员工管理系统</h1>
            <div class="user-info">
                <span>欢迎，<%= user.getUsername() %></span>
                <a href="../logout" class="btn btn-secondary">退出登录</a>
            </div>
        </div>
        
        <!-- 导航栏 -->
        <div class="nav">
            <a href="../dashboard">仪表板</a>
            <a href="./" class="active">员工管理</a>
            <a href="./add">添加员工</a>
        </div>
        
        <!-- 内容区域 -->
        <div class="content">
            <div class="card">
                <div class="card-header">
                    添加新员工
                </div>
                <div class="card-body">
                    <% if (request.getAttribute("error") != null) { %>
                        <div class="alert alert-danger">
                            <%= request.getAttribute("error") %>
                        </div>
                    <% } %>
                    
                    <form action="./add" method="post" id="employeeForm">
                        <div class="form-row" style="display: flex; gap: 20px;">
                            <div class="form-group" style="flex: 1;">
                                <label for="name">姓名 *</label>
                                <input type="text" id="name" name="name" class="form-control" required>
                            </div>
                            <div class="form-group" style="flex: 1;">
                                <label for="department">部门 *</label>
                                <select id="department" name="department" class="form-control" required>
                                    <option value="">请选择部门</option>
                                    <option value="技术部">技术部</option>
                                    <option value="市场部">市场部</option>
                                    <option value="人事部">人事部</option>
                                    <option value="财务部">财务部</option>
                                    <option value="行政部">行政部</option>
                                </select>
                            </div>
                        </div>
                        
                        <div class="form-row" style="display: flex; gap: 20px;">
                            <div class="form-group" style="flex: 1;">
                                <label for="position">职位 *</label>
                                <select id="position" name="position" class="form-control" required>
                                    <option value="">请选择职位</option>
                                    <option value="软件工程师">软件工程师</option>
                                    <option value="高级工程师">高级工程师</option>
                                    <option value="技术经理">技术经理</option>
                                    <option value="市场专员">市场专员</option>
                                    <option value="市场经理">市场经理</option>
                                    <option value="HR专员">HR专员</option>
                                    <option value="HR经理">HR经理</option>
                                    <option value="财务专员">财务专员</option>
                                    <option value="财务主管">财务主管</option>
                                    <option value="行政助理">行政助理</option>
                                    <option value="行政主管">行政主管</option>
                                </select>
                            </div>
                            <div class="form-group" style="flex: 1;">
                                <label for="salary">薪资 *</label>
                                <input type="number" id="salary" name="salary" class="form-control" 
                                       step="0.01" min="0" placeholder="请输入薪资" required>
                            </div>
                        </div>
                        
                        <div class="form-row" style="display: flex; gap: 20px;">
                            <div class="form-group" style="flex: 1;">
                                <label for="email">邮箱</label>
                                <input type="email" id="email" name="email" class="form-control" 
                                       placeholder="请输入邮箱地址">
                            </div>
                            <div class="form-group" style="flex: 1;">
                                <label for="phone">电话</label>
                                <input type="tel" id="phone" name="phone" class="form-control" 
                                       placeholder="请输入电话号码">
                            </div>
                        </div>
                        
                        <div class="form-group">
                            <label for="hireDate">入职时间 *</label>
                            <input type="date" id="hireDate" name="hireDate" class="form-control" required>
                        </div>
                        
                        <div class="form-group">
                            <button type="submit" class="btn btn-success">保存</button>
                            <a href="./" class="btn btn-secondary">取消</a>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
    
    <script>
        // 设置默认入职时间为今天
        document.getElementById('hireDate').valueAsDate = new Date();
        
        // 表单验证
        document.getElementById('employeeForm').addEventListener('submit', function(e) {
            const name = document.getElementById('name').value.trim();
            const department = document.getElementById('department').value;
            const position = document.getElementById('position').value;
            const salary = document.getElementById('salary').value;
            const hireDate = document.getElementById('hireDate').value;
            
            if (!name) {
                alert('请输入员工姓名');
                e.preventDefault();
                return;
            }
            
            if (!department) {
                alert('请选择部门');
                e.preventDefault();
                return;
            }
            
            if (!position) {
                alert('请选择职位');
                e.preventDefault();
                return;
            }
            
            if (!salary || salary <= 0) {
                alert('请输入有效的薪资');
                e.preventDefault();
                return;
            }
            
            if (!hireDate) {
                alert('请选择入职时间');
                e.preventDefault();
                return;
            }
        });
    </script>
</body>
</html>